﻿using System;
using System.Linq;
using Microsoft.WowAddonStudio.TocEditor;
using NUnit.Framework;

namespace WowProjectPackage.Tests.TocEditor
{
	/// <summary>
	/// Implements tests for <see cref="TocMetadata"/> class.
	/// </summary>
	[TestFixture]
	public class TocMetadataTest
	{
		private TocMetadata metadata;

		[SetUp]
		public void SetUp()
		{
			metadata = new TocMetadata();
		}

		[TearDown]
		public void TearDown()
		{
		}

		[Test]
		public void TestAddBasicMetadataWithNullValue()
		{
			metadata[TocTagName.Interface] = null;
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 1);
		}

		[Test]
		public void TestAddBasicMetadataWithEmptyValue()
		{
			metadata[TocTagName.Interface] = string.Empty;
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 1);
		}

		[Test]
		public void TestAddBasicMetadataWithPlainValue()
		{
			metadata[TocTagName.Interface] = "something";
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 1);
		}

		[Test]
		public void TestClear()
		{
			metadata[TocTagName.Interface] = string.Empty;
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 1);
			metadata.Clear();
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 0);
		}

		[Test]
		public void TestRemoveNonExisting()
		{
			metadata[TocTagName.Interface] = string.Empty;
			metadata[TocTagName.Version] = "1.0";
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 2);
			metadata.Remove(TocTagName.Url);
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 2);
		}

		[Test]
		public void TestRemoveExisting()
		{
			metadata[TocTagName.Interface] = string.Empty;
			metadata[TocTagName.Version] = "1.0";
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 2);
			metadata.Remove(TocTagName.Interface);
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 1);

			metadata.Remove(TocTagName.Version);
			Assert.IsNotNull(metadata.GetTags());
			Assert.AreEqual(metadata.GetTags().Count(), 0);
		}

		[Test]
		[ExpectedException(typeof (ArgumentNullException))]
		public void TestGetNullKey()
		{
			string value = metadata[null];
		}

		[Test]
		public void TestGetExistingKey()
		{
			metadata[TocTagName.Version] = "1.0";
			string value = metadata[TocTagName.Version];
			Assert.AreEqual(value, "1.0");
		}
	}
}